package com.yeyks.task;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeyks.common.constants.activity.RedisKeyPreConstant;
import com.yeyks.commonReference.append.activity.ActivityZhouJieLunService;
import com.yeyks.consumer.dal.domain.UserDataStat;
import com.yeyks.consumer.service.UserDataStatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.*;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @author shuai
 * @date 2019/11/07 19:15
 */
//@Component
//@Slf4j
public class ActivityZJLTask {

//    @Autowired
//    private RedisTemplate redisTemplate;
//    @Autowired
//    private UserDataStatService userDataStatService;
//    @Autowired
//    private ActivityZhouJieLunService activityZhouJieLunService;
//
//    /**
//     * 每天凌晨5分执行一次
//     */
//    @Scheduled(cron = "${schedule.activity.zjl}")
//    private void activityZJLTask() {
//        log.info("活动zjl定时任务开始-----------，time = {}", DateUtil.formatDateTime(new Date()));
//        String zjlCountByKey = getZJLCountByKey();
//        UserDataStat userDataStat = activityZhouJieLunService.getRedisActivityData(zjlCountByKey);
//        if (null == userDataStat) {
//            log.info("活动zjl定时任务读取redis数据为空");
//            return;
//        }
//        UserDataStat one = userDataStatService.getOne(new QueryWrapper<UserDataStat>().eq(UserDataStat.DATE, userDataStat.getDate()).last("limit 1"));
//        if (null == one) {
//            if (!userDataStatService.save(userDataStat)) {
//                log.info("活动zjl定时任务保存信息失败 userDataStat = {}", userDataStat);
//            } else {
//                redisTemplate.delete(zjlCountByKey);
//            }
//        }
//        log.info("活动zjl定时任务结束");
//    }
//
//    private String getZJLCountByKey() {
//        return RedisKeyPreConstant.STATISTICAL_DATA_PRE + RedisKeyPreConstant.STATISTICAL_DATA_MIDDLE_ACTIVITY + RedisKeyPreConstant.STATISTICAL_DATA_MIDDLE_ACTIVITY_END_ZHOUJIELUN_COUNT;
//    }
}
